package elog

import (
	"beergo/app/sys/documents"
	"encoding/json"
	"runtime"
	"strconv"
)

func Info(info interface{}) {
	_,file,line,ok:=runtime.Caller(1)
	if ok {

		log := new(documents.ErrorLog)
		log.File = file
		log.Line = strconv.Itoa(line)

		switch info.(type) {
		case string:
			log.Error = info.(string)
		case []byte:
			log.Error =string( info.([]byte))
		default:
			println("data type = unknown")
			str, _ := json.Marshal(info)
			log.Error = string(str)
		}
		log.Save()
	}
}

func Add(err error) {
	AddLog(err,1)
}
func AddLog(err error,skip int) {
	_,file,line,ok:=runtime.Caller(skip)
	if ok {
		log := new(documents.ErrorLog)
		log.File = file
		log.Line = strconv.Itoa(line)
		log.Error = err.Error()
		log.Save()
	}
}